﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RealState.BLL;
using RealState.BusinessObjects;
using log4net;
using RealState.Utils;

namespace RealState.W.AdminControl
{
    public partial class TradeTypeE : System.Web.UI.UserControl
    {
        private TradeTypesBLL m_TradeTypeBLL;
        private TradeTypes m_TradeTypesDO;
        protected ILog log = LogManager.GetLogger(typeof(TradeTypeE));
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
                {
                    m_TradeTypeBLL = new TradeTypesBLL();
                    m_TradeTypesDO = new TradeTypes();
                    try
                    {
                        m_TradeTypesDO = m_TradeTypeBLL.GetTradeTypes(Int32.Parse(Request.QueryString["ID"]));

                        txtTitle.Text = m_TradeTypesDO.Title;
                    }
                    catch (Exception ex)
                    {
                        log.Equals(ex.Message);
                    }
                    finally
                    {
                        m_TradeTypesDO = null;
                        m_TradeTypeBLL = null;
                    }
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            m_TradeTypeBLL = new TradeTypesBLL();
            m_TradeTypesDO = new TradeTypes();
            try
            {
                m_TradeTypesDO.Title = txtTitle.Text;
                m_TradeTypesDO.Id = Int32.Parse(Request.QueryString["ID"]);
                int result = m_TradeTypeBLL.UpdateTradeTypes(m_TradeTypesDO);
                if (result > 0)
                {
                    JavaScript.Success("Cập nhật thành công", Page, "TradeType.aspx");
                }
                else
                    JavaScript.Error("Có lỗi xảy ra ", Page);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
            finally
            {
                m_TradeTypeBLL = null;
                m_TradeTypesDO = null;
            }
        }
    }
}